package com.glsc.ngateway.opmanage.event;

import com.glsc.ngateway.opmanage.enums.TaskTypeUrlEnum;
import com.glsc.ngateway.opmanage.event.vo.TaskInfoEvent;
import com.glsc.ngateway.opmanage.service.task.TaskInfoService;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component
public class TaskInfoEventListener implements ApplicationListener<TaskInfoEvent> {

    @Resource
    private TaskInfoService taskInfoService;


    @Override
    public void onApplicationEvent(TaskInfoEvent event) {
        TaskTypeUrlEnum taskTypeUrlEnum = event.getTaskTypeUrlEnum();
        if (event.getOp().equals("0")) {
            //创建待办
            taskInfoService.create(event.getBusinessId(), event.getName(), taskTypeUrlEnum.getRoleCode(), taskTypeUrlEnum.getShotUrl() + event.getBusinessId(), taskTypeUrlEnum.getType());
        } else if (event.getOp().equals("1")) {
            //完成待办
            taskInfoService.finishTaskByBusinessIdAndType(event.getBusinessId(), taskTypeUrlEnum.getType());
        }


    }
}
